<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { useCommonStore, useUserStore } from './store';
import { tabbarStore } from '@/components/fg-tabbar/tabbar'
// import { TUILogin } from '@tencentcloud/tui-core'

// #ifdef APP-PLUS || H5
// import { TUIChatKit } from './TUIKit';
// TUIChatKit.init();
// #endif

onLaunch((options) => {
  console.log('onLaunch options', options)
  const { query } = options || {};
  const { instrId, source } = query || {};

  const user = useUserStore();
  user.instrId = instrId;
  user.source = source;
  user.isLogined && user.handleTUILogin();

  const useCommon = useCommonStore();
  const currentTime = +new Date();
  const expirationDate = 5 * 60 * 1000; // 过期时间
  const isExpired = currentTime - (+useCommon.commonState.dictInfoTemp) > expirationDate;

  // 获取字典
  if (isExpired || JSON.stringify(useCommon.commonState.dictInfo) === '{}') {
    useCommon.getDictInfoList();
  }
 
  // 获取地区信息
  if (isExpired || !useCommon.commonState.regionInfo.length) {
    useCommon.getRegionInfoGetList();
  }

  useCommon.queryConfig();
  useCommon.queryChargeConfig();
  useCommon.queryPhoneLoginConfig();
  
  // 获取ip地址信息
  useCommon.getBaiduyunIp2address();
  
  // #ifdef MP-WEIXIN
  tabbarStore.setCurIdx(0);
  // #endif
})
onShow(() => {
  const user = useUserStore();
  const expirationDate = 50 * 60 * 1000; // 过期时间50分钟重新登录
  const currentTime = +new Date();
  
  // if (currentTime - user.loginTime > expirationDate) {
  //   console.log('清除信息')
  //   user.clearUserInfo();
  // }
  console.log('App Show')
})
onHide(() => {
  console.log('App Hide')
})
</script>

<style lang="scss">
/* stylelint-disable selector-type-no-unknown */
button::after {
  border: none;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 单行省略，优先使用 unocss: text-ellipsis
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 两行省略
.ellipsis-2 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

// 三行省略
.ellipsis-3 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
</style>
